package test3;

import test3.definitions.FileDefinition;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Aug 1, 2007
 * Time: 9:20:04 PM
 * Revision: 0
 */
public class FileParser
{
    private char[] dataBuf;
    private int dataPos;
    Tokenizator parser;
    FileDefinition fileDef;


    public FileParser()
    {
        String toParse = "" +
                "package gigel;" +
                "public class gigel\n" +
                "{\n" +
                "}";

        dataBuf = toParse.toCharArray();
        dataPos = 0;

        fileDef = new FileDefinition();
        
        String token = parser.getToken();

        {
            if (token.equals("package"))
            parsePackage();
            else
            if (token.equals("import"))
            parseImport();
            else
            parseClass();
        }
    }

    void error(String s)
    {
        System.out.println("ERROR: " + s);
    }

    void parsePackage()
    {
        String token;
        String name = "";
        parser.getToken(); //get out the "package";
        token = parser.getToken();

        while (true)
        {
            if (token.length() == 0)
            {
                error("Expecting package name, found " + parser.peekChar());
                parser.consumeTo("; ");
                return;
            }

            name += token;

            if (parser.peekChar() == '.')
            {
                parser.getChar();
                name += '.';
            }
            else
                if (parser.peekChar() == ';')
                {
                    parser.getChar();
                    fileDef.setPackageName(name);
                }
        }
    }

    void parseImport()
    {

    }

    void parseClass()
    {
        
    }
}
